<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>我正在审批的流程</title>
    <#include "/pubHeadStyleTree.html">
</head>
<body>

<div style="position: relative;height: 100%;">
    <div class="ccpui-trees" >
        <p class="isShowTree colorSwitch">
            <span style="float: left;color: #fff">&nbsp;&nbsp;待办事宜</span>
            <i layadmin-event="treeFlexible" class="layui-icon layui-icon-prev"></i>
        </p>
        <div style="margin-top: 6px;" >
            <ul class="ccpui-iconTree iconTrees">
                <li><a class="iconfont iconshuaxin- zTree-refresh" title="刷新"></a></li>
                <li><a class="iconfont iconwenjianjia1-copy zTree-triangle-d" title="展开"></a></li>
                <li><a class="iconfont iconfolder1 zTree-triangle-r" title="收起"></a></li>
                <input type="text" style="width: 50%" class="catZtreeValue">
            </ul>
            <ul id="treeSelectGlobalType" class="ztree ccpui-listZtree"></ul>
        </div>
    </div>
    <div class="ccpui-coreContent" style="position: absolute;top:10px;right:10px;bottom: 0;left: 250px">
        <table id="pendingMattersTask" lay-filter="pendingMattersTask" ></table>
    </div>
</div>

<style>
    .iconTrees li {
        display: inline-block;
        margin: 6px 4px;
        cursor: pointer;
    }
    .layui-table-tool-temp{
        padding-right: 0px;
    }
    @media screen and (max-width: 1440px) {
        .table-top-filter label.layui-form-label {
            width: 88px;
        }
        .table-top-filter div input {
            width: 118px;
        }
    }

</style>
<script type="text/html" id="headerToolsBar">
    <div class="ccpui-enterSel">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm" lay-event="query">
            <i class="layui-icon layui-icon-search"></i>
            <span>查询</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="reset">
            <i class="layui-icon layui-icon-refresh"></i>
            <span>重置</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="batchHandover">
            <i class="layui-icon layui-icon-file-b"></i>
            <span>批量交接</span>
        </a>
    </div>
    <form class="layui-form" action="" lay-filter="pendingMatterQueryForm" style="margin-top:10px">
        <div class="table-top-filter">
            <div class="table-filter-alone">
                <label class="layui-form-label">事项名称</label>
                <input type="text" name="Q_subject_SL" id="subject" class="layui-input filter-value"
                       placeholder="事项名称"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">流程名称</label>
                <input type="text" name="Q_processName_SL" id="processName" class="layui-input filter-value"
                       placeholder="流程名称"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">创建人</label>
                <input type="text" name="Q_creator_SL" id="creator" class="layui-input filter-value"
                       placeholder="创建人"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">待办类型</label>
                <select name="Q_description_S" id="description" class="layui-input filter-value"
                        placeholder="待办状态">
                    <option value="">所有</option>
                    <option value="-1,3,24">待办</option>
                    <option value="21">转办</option>
                    <option value="15">沟通意见</option>
                    <option value="26">代理</option>
                    <option value="38">流转意见</option>
                    <option value="39">流转中</option>
                </select>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">状态</label>
                <select name="Q_taskStatus_S" id="taskStatus" class="layui-input filter-value" placeholder="状态">
                    <option value="">所有</option>
                    <option value="1">审批中</option>
                    <option value="5">已撤销</option>
                    <option value="6">已驳回</option>
                    <option value="7">已追回</option>
                </select>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">创建时间</label>
                <input type="text" name="Q_createTime_DL" id="createTime" class="layui-input filter-value"
                       placeholder="开始时间"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label" style="text-align: center;">至</label>
                <input type="text" name="Q_endTime_DG" id="endTime" class="layui-input filter-value"
                       placeholder="结束时间"/>
            </div>
        </div>
    </form>
    </div>
</script>

<script type="text/html" id="managementBar">
    <a class="layui-btn layui-btn-xs" lay-event="handover">交接</a>
</script>


<script>

    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'layer', 'form', 'util', 'common', 'commons','totalFilter', 'laydate'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var util = layui.util;
        var common = layui.common;
        var commons = layui.commons;
        var $ = layui.$;
        var setter = layui.setter;
        var totalFilter = layui.totalFilter;
        var laydate = layui.laydate;
        var tableH=commons.tabHeight();
        catZtree();
        loadTable(serverPath.workflowPath + setter.workflowLinkPath + 'flowHandover/list/allPendingMatters');

        function catZtree() {
            var typeIds = [];
            $.ajax({
                url: serverPath.workflowPath + setter.workflowLinkPath + 'flowHandover/list/allPendingMatters',
                type: "post",
                dataType: 'json',
                async: false,
                success: function (res) {
                    if(res.code === 0){
                        $.each(res.data, function (k, v) {
                            typeIds.push(v.typeId)
                        });
                    }
                },
                error: function () {
                }
            });
            $.ajax({
                url: serverPath.workflowPath + "/system/globalType/list",
                type: "post",
                dataType: 'json',
                async: false,
                data: {"catKey": "FLOW_TYPE", "hasRoot": 1},
                success: function (data) {
                    var zNodes = [];
                    zNodes.push(data.data[0]);
                    $.each(data.data, function (k, v) {
                        if (ArrayIndexOf(typeIds,v.typeId) > -1) {
                            zNodes.push(v)
                        }
                    });
                    var setting = {
                        view: {
                            showLine: false,
                            nameIsHTML: true, //允许name支持html
                            selectedMulti: false
                        },
                        edit: {
                            enable: false,
                            editNameSelectAll: false
                        },
                        data: {
                            simpleData: {
                                enable: true,
                                idKey: "typeId",
                                pIdKey: "parentId"

                            },
                            key: {
                                name: "typeName"
                            }
                        },

                        callback: {
                            onClick: onClickType,
                        }
                    };
                    $.fn.zTree.init($('#treeSelectGlobalType'), setting, zNodes);
                    component.fuzzySearch('treeSelectGlobalType', '.catZtreeValue', null, true); //初始化模糊搜索方法
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("暂无数据，请稍后操作！" + XMLHttpRequest.status);
                },
            });
        }

        function onClickType(event, treeId, treeNode) {
            var selectTypeId = treeNode.typeId;
            var url = serverPath.workflowPath + setter.workflowLinkPath + 'task/list/pendingMatters?typeId=' + selectTypeId;
            if (null == treeNode.parentId) {
                url = serverPath.workflowPath + setter.workflowLinkPath + 'task/list/pendingMatters';
            }
            loadTable(url);
        }
        //封装一个方法实现indexOf的功能
        function ArrayIndexOf(arr,value){
            //检测value在arr中出现的位置
            for(var i=0;i<arr.length;i++){
                if(arr[i]===value){
                    return i;
                }
            }
            return -1;
        }
        //展开
        $(".iconTrees .zTree-triangle-d").click(function () {
            $.fn.zTree.getZTreeObj("treeSelectGlobalType").expandAll(true);
        });
        //收起
        $(".iconTrees .zTree-triangle-r").click(function () {
            $.fn.zTree.getZTreeObj("treeSelectGlobalType").expandAll(false);
        });
        //刷新
        $(".iconTrees .zTree-refresh").click(function () {
            catZtree();
        });

        var warningSet = $.parseJSON('${warningSet}');
        var currentUserId = '${currentUserId}';
        var userPrivacyLevel = '${userPrivacyLevel}';
        //第一个实例
        function loadTable(url) {
            table.render({
                elem: '#pendingMattersTask'
                , cellMinWidth: 80
                , title: '待办事宜'
                , url: url
                , height: tableH
                , method: 'post'
                , toolbar: '#headerToolsBar'
                ,defaultToolbar: ['filter', 'print']
                , page: true
                ,autoSort: false
                , cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    , {
                        field: 'subject',
                        title: '事项名称',
                        sort: true,
                        minWidth: 330,
                        align: 'center',
                        event: 'detail',
                        templet: function (v) {
                            var priority = v.priority;
                            var color;
                            for(var i=0;i<warningSet.length;i++){
                                if(priority==warningSet[i].priority){
                                    color = warningSet[i].color;
                                    break;
                                }
                            }
                            if (v.hasRead == 0) {
                                return "<img src=\"${ctx}/images/mail/msg_own.png\">&nbsp;<a href='javascript:;' style='color: "+color+";text-decoration: underline;'>" + v.subject+"</a>";
                            } else {
                                return "<img src=\"${ctx}/images/mail/msg_none.png\">&nbsp;<a href='javascript:;' style='color: "+color+";text-decoration: underline;'>" + v.subject+"</a>";
                            }
                        }
                    }
                    , {field: 'processName', title: '流程名称', sort: true, align: 'center'}
                    , {
                        field: 'creator',
                        title: '创建人',
                        sort: true,
                        align: 'center',
                        style: "cursor:pointer;color:blue;text-decoration:underline",
                        event: 'creator'
                    }
                    , {
                        field: 'create_Time_', title: '创建时间', minWidth: 200,sort: true, align: 'center', templet: function (d) {
                            return util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss");
                        }
                    }
                    , {field: 'taskStatus', title: '状态', sort: true, align: 'center', templet: '#table-taskStatus'}
                    , {field: 'description_', title: '待办类型', sort: true, align: 'center', templet: '#table-description'}
                    , { title: '管理', toolbar: '#managementBar',align: 'center'}
                ]]
                ,done:function () {
                    commons.reflashDate({startName: '#createTime', endName: '#endTime'});
                    common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel')
                }
            });
            totalFilter.init('pendingMattersTask');
        }

        //弹出用户选择框
        function popSingleUserDialog(selectedIds,dataPrivacyLevel){
            var userSelectorWin;
            var body;
            parent.layer.open({
                type: 2,
                title: '人员选择器',
                area: ['760px','585px'],
                btn:["保存","取消","撤销"],
                content:serverPath.systemPath + setter.sysLinkPath+ "dialog/view/singleSysUserDialog?dataPrivacyLevel=" + dataPrivacyLevel,
                success: function(layero, index){
                    body = parent.layer.getChildFrame('body',index);
                    userSelectorWin = parent.window[layero.find('iframe')[0]['name']];
                },
                yes:function (index,layero) {
                    //执行iframe页的save方法
                    userSelectorWin.saveData(index);
                    var theUserList = body.find("input[name=selectUser]").val();
                    var item = JSON.parse(theUserList);
                    var receiverId = item.userId;
                    if(receiverId==undefined||receiverId==''){
                        parent.layer.alert("请选择被交接人!", '提示信息');
                        return;
                    }
                    if(currentUserId==receiverId){
                        parent.layer.alert("交接人不能选择自己!", '提示信息');
                        return;
                    }
                    parent.layer.confirm("确认选择此人进行交接吗?",{title: '交接确认',icon:3},function(indexConfirm){
                        parent.layer.close(indexConfirm);
                        handOver(selectedIds,receiverId,index);
                    });
                },
                btn3:function (index, layero) {
                    userSelectorWin.cancelData(index);
                    return false //开启该代码可禁止点击该按钮关闭
                }
            });
        }
        /**
         * 交接任务
         * taskIds 任务id
         * receiverId 被交接人id
         * userDialogIndex 人员选择器窗口index
         */
        function handOver(taskIds,receiverId,userDialogIndex){
            $.ajax({
                url: serverPath.workflowPath + setter.workflowLinkPath + "flowHandover/handoverWork" ,
                data:{
                    taskIds:taskIds,
                    receiverId:receiverId
                },
                async: false,
                type: 'post',
                dataType:'json',
                success: function (result) {
                    if (result.code === 0) {
                        //交接成功
                        parent.layer.alert(result.msg, function (index2) {
                            //关闭提示框
                            parent.layer.close(index2);
                            //关闭人员选择器弹框
                            parent.layer.close(userDialogIndex);
                            //刷新整个页面
                            location.reload();
                        });
                    } else {
                        //弹出失败提示
                        parent.layer.alert(result.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("请求失败！" + XMLHttpRequest.status);
                },
            });
        }

        table.on('toolbar(pendingMattersTask)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data; //获取选中行数据
            switch (obj.event) {
                case 'query':
                    common.tableConditionRender("pendingMattersTask", "pendingMatterQueryForm", {where: {}}, false);
                    break;
                case 'reset':
                    common.tableConditionRender("pendingMattersTask", "pendingMatterQueryForm", {where: {}}, true);
                    break;
                case 'batchHandover':
                    if (data.length === 0) {
                        layer.msg('请先选择一行数据！');
                    } else {
                        layer.confirm("批量交接时，交接人的密级不得低于您，确认批量交接吗?",{title: '交接确认',icon:3},function(){
                            var selectedIdArray = [];
                            for (var i = 0; i < data.length; i++) {
                                selectedIdArray.push(data[i].id);
                            }
                            var selectedIds = selectedIdArray.join(",");
                            popSingleUserDialog(selectedIds,userPrivacyLevel);
                        });
                    }
                    break;
            }
        });

        table.on('tool(pendingMattersTask)', function (obj) {
            var event = obj.event,
                data = obj.data;
            var isNeedReload=true;
            switch (event) {
                case 'detail':
                    parent.layer.open({
                        type: 2,
                        title: "流程任务-["+data.name+"]明细",
                        area: ['1300px', '680px'],
                        content: serverPath.workflowPath + setter.workflowLinkPath +"task/view/toStart?taskId=" + data.id + "&instanceId=" + data.processInstanceId+"&handover=true",
                        cancel: function () {
                            isNeedReload = false;
                        },
                        end: function(index, layero){
                            if (isNeedReload) {
                                table.reload('pendingMattersTask', {
                                    page: {
                                        curr: 1
                                    }
                                });
                                layer.close(index);
                                totalFilter.init('pendingMattersTask');
                            }
                            return false;
                        }
                    });
                    break;
                case 'creator':
                    layer.open({
                        type: 2,
                        area: ['1000px', '620px'],
                        title: ['查看用户信息'],
                        content:serverPath.systemPath+ setter.sysLinkPath+'sysUser/view/view?userId=' + data.creatorId
                    });
                    break;
                case 'handover':
                    layer.confirm("确认交接吗?",{title: '交接确认',icon:3},function(index){
                        layer.close(index);
                        // 获取密级
                        $.ajax({
                            url: serverPath.workflowPath + setter.workflowLinkPath+"processRun/getPrivacyLevelByRunId?runId="+data.runId,
                            type: "get",
                            dataType: 'json',
                            success: function (privacyLevel) {
                                popSingleUserDialog(data.id,privacyLevel);
                            }
                        });
                    });
                    break;
            }
        });

        common.tableSort("pendingMattersTask",{show:window.Initialization});
        commons.reflashDate({startName: '#createTime', endName: '#endTime'});
        window.Initialization = function () {
            commons.reflashDate({startName: '#createTime', endName: '#endTime'});
        };
    });
</script>
<script type="text/html" id="table-taskStatus">
    {{# if(d.taskStatus == 1) { }}
    审批中
    {{# } else if(d.taskStatus == 5) { }}
    已撤回
    {{# } else if(d.taskStatus == 6) { }}
    已驳回
    {{# } else if(d.taskStatus == 7) { }}
    已追回
    {{# } else { }}
    未知
    {{# } }}
</script>
<script type="text/html" id="table-description">
    {{# if(d.description == -1 || d.description==3 || d.description==24) { }}
    待办
    {{# } else if(d.description == 15) { }}
    沟通意见
    {{# } else if(d.description == 21) { }}
    转办
    {{# } else if(d.description == 26) { }}
    代理
    {{# } else if(d.description == 38) { }}
    流转意见
    {{# } else if(d.description == 39) { }}
    流转中
    {{# } else { }}
    未知
    {{# } }}
</script>
</body>
</html>
<link rel="stylesheet" href="${ctx}/css/font/iconfontie.css" media="all"/>
<link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
